package com.yc.system.mapper;

import com.yc.system.dto.RegisterInfo;
import com.yc.system.dto.UserDto;
import com.yc.system.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author 1850140986@qq.com
 * @since 2022-12-03
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from t_user where user_id=#{userId}")
    User getUserByUserId(int userId);

    @Select("SELECT  * FROM  t_user ORDER BY RAND() LIMIT 1")
    User getUserRandom();

    @Select("SELECT  * FROM  t_user ORDER BY RAND() LIMIT #{num}")
    List<User> getUsersRandom(int num);

    @Select("select ppicture_addr from t_user where user_id=#{userId}")
    String getPpictureAddrByUserId(int userId);

    @Update("update t_user set ppicture_addr=#{reqFullFileName} where user_id=#{userId}")
    int changePpictureAddr(int userId, String reqFullFileName);

    @Select("select * from t_user where user_id=#{userId}")
    UserDto getUserByUserDtoId(int userId);

    @Insert("insert into t_user (username,password,phone,email) values (#{username},#{password},#{phone},#{email})")
    int register(User registerInfo);

    @Select("select user_id from t_user where email=#{email}")
    Long getUserByEmail(String email);

    @Select("select * from t_user where username=#{username}")
    User getUserByUsername(String username);

    @Select("select user_id from t_user where username=#{username}")
    Long getUserIdByUsername(String username);

    @Update("update t_user set name=#{name},username=#{username},address=#{address},age=#{age},email=#{email},desctiption=#{desctiption},qq=#{qq},phone=#{phone},sex=#{sex} where user_id=#{userId}")
    int updataByUserInfo(User user);

    @Select("select count(1) from t_user_role where user_id=#{userId} and role_id=2 and deleted=0")
    int getAdminByUserId(Integer userId);
}
